<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
        <style>
            h1{
                color: red;
                text-align: center;
                font-size: 100px;
            }
            button{
                float: left;
                width: 99px;
                height: 37px;
                background: #38f;
                outline: none;
                border: none;
                color: #fff;
                cursor: pointer;
                font-weight: bold;
                font-size: 17px;
            }
            span{
                float: left;
                height: 10px;
                width: 830px;
            }
            div{
                margin: auto;
                background: url('imges/1.jpg');
            }
            div img{
                height: 800px;
            }
        </style>
    </head>
    <body>
         
        <div>
            <h1 id="txt">谁是大傻逼</h1>
            <span></span>
            <button id="start">开始</button>
            <button id="stop">结束</button>
        </div>
 
        <script>
            var a=document.getElementById('start');
            var b=document.getElementById('stop');
            var c=document.getElementById('txt');
            var timer;

            // 把数据提炼出来,放到数组中
            var list=['董烨坪','陈子键','廖泽昊','陈彦忠','胡智荣','危嘉颖']
            // 获取数组中的某一个数据，数组名[下标]
            console.log(list[0]);
            // 获取数组长度  数组名.length
            console.log(list.length);
 
            a.onclick=function(){
                // 停止定时器 clearInterval(定时器名字)
                clearInterval(timer)
 
                timer=setInterval(function(){
                    // c.innerHTML=parseInt(Math.random()*11)

                    // 产生随机数
                    var n=parseInt(Math.random()*list.length);
                    c.innerHTML=list[n];
                },100)
            }
 
            // 点击后停止定时器
            b.onclick=function(){
                // 停止定时器 clearInterval(定时器名字)
                clearInterval(timer)
                // 内定中奖内容
                c.innerHTML=list[list.length-1];
            }
        </script>
    </body>
</html>